﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Slja.DBUtility;
using Slja.Model.Platform;
using System.Text.RegularExpressions;
using Slja.DAL.Common;
namespace Slja.DAL.Platform
{
        /// <summary>
        /// 数据访问类:User
        /// </summary>
        public partial class UserDAL
        {
            public UserDAL()
            { }
            #region  Method
            /// <summary>
            /// 是否存在该记录
            /// </summary>
            public bool Exists(int UserID)
            {
                StringBuilder strSql = new StringBuilder();
                strSql.Append("select count(1) from sys_User");
                strSql.Append(" where UserID=@UserID");
                SqlParameter[] parameters = {
					new SqlParameter("@UserID", SqlDbType.Int,4)
			};
                parameters[0].Value = UserID;

                return DbHelperSQL.Exists(strSql.ToString(), parameters);
            }
            public UserModel GetManagerFromCity(string cityid)
            {
                SqlParameter[] parms = new SqlParameter[1];
                parms[0] = new SqlParameter("@cityid",SqlDbType.Int);                    
                parms[0].Value  =int.Parse(cityid);
                DataSet ds = DbHelperSQL.RunProcedure("biz_FindPrjManger", parms,"usertbl");
                UserModel model = null;
                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count>0)
                {
                    model = new UserModel();
                    AssignUserModel(ds.Tables[0].Rows[0], model);
                }
                return model; 
            }
            public DataTable GetManagerFromCityAndKeyword(string cityid, string keyword)
            {
                    Regex regChz2 = new Regex(@"[\u0391-\uFFE5]{2,}");//2个以上的汉字
                    Regex regEng2 = new Regex(@"[A-Z,a-z]{2,}");//2个以上的拼音字母

                    StringBuilder sb = new StringBuilder(@"select b.UserID,b.U_CName from  dbo.biz_CityPrjManager a inner join dbo.sys_User b 
                        on a.UserID = b.UserID and a.[Type]=1 ");
                    
                   
                    if (!string.IsNullOrEmpty(cityid))
                    {
                        sb.Append(" and a.CityID='" + cityid + "'");
                    }
                    sb.Append(" and (1=1");
                    if (regChz2.IsMatch(keyword))
                    {
                        sb.Append(" AND U_CName like '" + keyword + "%'");
                    }
                    if (regEng2.IsMatch(keyword))
                    {
                        sb.Append(" AND U_EName like '" + keyword + "%'");
                    }
                    sb.Append(")");
                    DataSet ds = DbHelperSQL.Query(sb.ToString());
                    return ds.Tables[0];             
               
            }

            /// <summary>
            /// 增加一条数据
            /// </summary>
            public int Add(Slja.Model.Platform.UserModel model)
            {
                StringBuilder strSql = new StringBuilder();
                strSql.Append("insert into sys_User(");
                strSql.Append("U_LoginName,U_Password,U_CName,U_EName,U_GroupID,U_Email,U_Type,U_Status,U_Licence,U_Mac,U_Remark,U_IDCard,U_Sex,U_BirthDay,U_MobileNo,U_UserNO,U_WorkStartDate,U_WorkEndDate,U_CompanyMail,U_Title,U_Extension,U_HomeTel,U_PhotoUrl,U_DateTime,U_LastIP,U_LastDateTime,U_ExtendField)");
                strSql.Append(" values (");
                strSql.Append("@U_LoginName,@U_Password,@U_CName,@U_EName,@U_GroupID,@U_Email,@U_Type,@U_Status,@U_Licence,@U_Mac,@U_Remark,@U_IDCard,@U_Sex,@U_BirthDay,@U_MobileNo,@U_UserNO,@U_WorkStartDate,@U_WorkEndDate,@U_CompanyMail,@U_Title,@U_Extension,@U_HomeTel,@U_PhotoUrl,@U_DateTime,@U_LastIP,@U_LastDateTime,@U_ExtendField)");
                strSql.Append(";select @@IDENTITY");
                SqlParameter[] parameters = {
					new SqlParameter("@U_LoginName", SqlDbType.NVarChar,20),
					new SqlParameter("@U_Password", SqlDbType.VarChar,32),
					new SqlParameter("@U_CName", SqlDbType.NVarChar,20),
					new SqlParameter("@U_EName", SqlDbType.VarChar,50),
					new SqlParameter("@U_GroupID", SqlDbType.Int,4),
					new SqlParameter("@U_Email", SqlDbType.VarChar,100),
					new SqlParameter("@U_Type", SqlDbType.TinyInt,1),
					new SqlParameter("@U_Status", SqlDbType.TinyInt,1),
					new SqlParameter("@U_Licence", SqlDbType.VarChar,30),
					new SqlParameter("@U_Mac", SqlDbType.VarChar,50),
					new SqlParameter("@U_Remark", SqlDbType.NVarChar,200),
					new SqlParameter("@U_IDCard", SqlDbType.VarChar,30),
					new SqlParameter("@U_Sex", SqlDbType.TinyInt,1),
					new SqlParameter("@U_BirthDay", SqlDbType.DateTime),
					new SqlParameter("@U_MobileNo", SqlDbType.VarChar,15),
					new SqlParameter("@U_UserNO", SqlDbType.VarChar,20),
					new SqlParameter("@U_WorkStartDate", SqlDbType.DateTime),
					new SqlParameter("@U_WorkEndDate", SqlDbType.DateTime),
					new SqlParameter("@U_CompanyMail", SqlDbType.VarChar,255),
					new SqlParameter("@U_Title", SqlDbType.Int,4),
					new SqlParameter("@U_Extension", SqlDbType.VarChar,10),
					new SqlParameter("@U_HomeTel", SqlDbType.VarChar,20),
					new SqlParameter("@U_PhotoUrl", SqlDbType.NVarChar,255),
					new SqlParameter("@U_DateTime", SqlDbType.DateTime),
					new SqlParameter("@U_LastIP", SqlDbType.VarChar,15),
					new SqlParameter("@U_LastDateTime", SqlDbType.DateTime),
					new SqlParameter("@U_ExtendField", SqlDbType.NText)};
                parameters[0].Value = model.U_LoginName;
                parameters[1].Value = model.U_Password;
                parameters[2].Value = model.U_CName;
                parameters[3].Value = model.U_EName;
                parameters[4].Value = model.U_GroupID;
                parameters[5].Value = model.U_Email;
                parameters[6].Value = model.U_Type;
                parameters[7].Value = model.U_Status;
                parameters[8].Value = model.U_Licence;
                parameters[9].Value = model.U_Mac;
                parameters[10].Value = model.U_Remark;
                parameters[11].Value = model.U_IDCard;
                parameters[12].Value = model.U_Sex;
                parameters[13].Value = model.U_BirthDay;
                parameters[14].Value = model.U_MobileNo;
                parameters[15].Value = model.U_UserNO;
                parameters[16].Value = model.U_WorkStartDate;
                parameters[17].Value = model.U_WorkEndDate;
                parameters[18].Value = model.U_CompanyMail;
                parameters[19].Value = model.U_Title;
                parameters[20].Value = model.U_Extension;
                parameters[21].Value = model.U_HomeTel;
                parameters[22].Value = model.U_PhotoUrl;
                parameters[23].Value = model.U_DateTime;
                parameters[24].Value = model.U_LastIP;
                parameters[25].Value = model.U_LastDateTime;
                parameters[26].Value = model.U_ExtendField;

                object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
                if (obj == null)
                {
                    return 0;
                }
                else
                {
                    return Convert.ToInt32(obj);
                }
            }
            /// <summary>
            /// 更新一条数据
            /// </summary>
            public bool Update(Slja.Model.Platform.UserModel model)
            {
                StringBuilder strSql = new StringBuilder();
                strSql.Append("update sys_User set ");
                strSql.Append("U_LoginName=@U_LoginName,");
                strSql.Append("U_Password=@U_Password,");
                strSql.Append("U_CName=@U_CName,");
                strSql.Append("U_EName=@U_EName,");
                strSql.Append("U_GroupID=@U_GroupID,");
                strSql.Append("U_Email=@U_Email,");
                strSql.Append("U_Type=@U_Type,");
                strSql.Append("U_Status=@U_Status,");
                strSql.Append("U_Licence=@U_Licence,");
                strSql.Append("U_Mac=@U_Mac,");
                strSql.Append("U_Remark=@U_Remark,");
                strSql.Append("U_IDCard=@U_IDCard,");
                strSql.Append("U_Sex=@U_Sex,");
                strSql.Append("U_BirthDay=@U_BirthDay,");
                strSql.Append("U_MobileNo=@U_MobileNo,");
                strSql.Append("U_UserNO=@U_UserNO,");
                strSql.Append("U_WorkStartDate=@U_WorkStartDate,");
                strSql.Append("U_WorkEndDate=@U_WorkEndDate,");
                strSql.Append("U_CompanyMail=@U_CompanyMail,");
                strSql.Append("U_Title=@U_Title,");
                strSql.Append("U_Extension=@U_Extension,");
                strSql.Append("U_HomeTel=@U_HomeTel,");
                strSql.Append("U_PhotoUrl=@U_PhotoUrl,");
                strSql.Append("U_DateTime=@U_DateTime,");
                strSql.Append("U_LastIP=@U_LastIP,");
                strSql.Append("U_LastDateTime=@U_LastDateTime,");
                strSql.Append("U_ExtendField=@U_ExtendField");
                strSql.Append(" where UserID=@UserID");
                SqlParameter[] parameters = {
					new SqlParameter("@U_LoginName", SqlDbType.NVarChar,20),
					new SqlParameter("@U_Password", SqlDbType.VarChar,32),
					new SqlParameter("@U_CName", SqlDbType.NVarChar,20),
					new SqlParameter("@U_EName", SqlDbType.VarChar,50),
					new SqlParameter("@U_GroupID", SqlDbType.Int,4),
					new SqlParameter("@U_Email", SqlDbType.VarChar,100),
					new SqlParameter("@U_Type", SqlDbType.TinyInt,1),
					new SqlParameter("@U_Status", SqlDbType.TinyInt,1),
					new SqlParameter("@U_Licence", SqlDbType.VarChar,30),
					new SqlParameter("@U_Mac", SqlDbType.VarChar,50),
					new SqlParameter("@U_Remark", SqlDbType.NVarChar,200),
					new SqlParameter("@U_IDCard", SqlDbType.VarChar,30),
					new SqlParameter("@U_Sex", SqlDbType.TinyInt,1),
					new SqlParameter("@U_BirthDay", SqlDbType.DateTime),
					new SqlParameter("@U_MobileNo", SqlDbType.VarChar,15),
					new SqlParameter("@U_UserNO", SqlDbType.VarChar,20),
					new SqlParameter("@U_WorkStartDate", SqlDbType.DateTime),
					new SqlParameter("@U_WorkEndDate", SqlDbType.DateTime),
					new SqlParameter("@U_CompanyMail", SqlDbType.VarChar,255),
					new SqlParameter("@U_Title", SqlDbType.Int,4),
					new SqlParameter("@U_Extension", SqlDbType.VarChar,10),
					new SqlParameter("@U_HomeTel", SqlDbType.VarChar,20),
					new SqlParameter("@U_PhotoUrl", SqlDbType.NVarChar,255),
					new SqlParameter("@U_DateTime", SqlDbType.DateTime),
					new SqlParameter("@U_LastIP", SqlDbType.VarChar,15),
					new SqlParameter("@U_LastDateTime", SqlDbType.DateTime),
					new SqlParameter("@U_ExtendField", SqlDbType.NText),
					new SqlParameter("@UserID", SqlDbType.Int,4)};
                parameters[0].Value = model.U_LoginName;
                parameters[1].Value = model.U_Password;
                parameters[2].Value = model.U_CName;
                parameters[3].Value = model.U_EName;
                parameters[4].Value = model.U_GroupID;
                parameters[5].Value = model.U_Email;
                parameters[6].Value = model.U_Type;
                parameters[7].Value = model.U_Status;
                parameters[8].Value = model.U_Licence;
                parameters[9].Value = model.U_Mac;
                parameters[10].Value = model.U_Remark;
                parameters[11].Value = model.U_IDCard;
                parameters[12].Value = model.U_Sex;
                parameters[13].Value = model.U_BirthDay;
                parameters[14].Value = model.U_MobileNo;
                parameters[15].Value = model.U_UserNO;
                parameters[16].Value = model.U_WorkStartDate;
                parameters[17].Value = model.U_WorkEndDate;
                parameters[18].Value = model.U_CompanyMail;
                parameters[19].Value = model.U_Title;
                parameters[20].Value = model.U_Extension;
                parameters[21].Value = model.U_HomeTel;
                parameters[22].Value = model.U_PhotoUrl;
                parameters[23].Value = model.U_DateTime;
                parameters[24].Value = model.U_LastIP;
                parameters[25].Value = model.U_LastDateTime;
                parameters[26].Value = model.U_ExtendField;
                parameters[27].Value = model.UserID;

                int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
                if (rows > 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }

            /// <summary>
            /// 删除一条数据
            /// </summary>
            public bool Delete(int UserID)
            {

                StringBuilder strSql = new StringBuilder();
                strSql.Append("delete from sys_User ");
                strSql.Append(" where UserID=@UserID");
                SqlParameter[] parameters = {
					new SqlParameter("@UserID", SqlDbType.Int,4)
			};
                parameters[0].Value = UserID;

                int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
                if (rows > 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            /// <summary>
            /// 批量删除数据
            /// </summary>
            public bool DeleteList(string UserIDlist)
            {
                StringBuilder strSql = new StringBuilder();
                strSql.Append("delete from sys_User ");
                strSql.Append(" where UserID in (" + UserIDlist + ")  ");
                int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
                if (rows > 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }


            /// <summary>
            /// 得到一个对象实体
            /// </summary>
            public Slja.Model.Platform.UserModel GetModel(int UserID)
            {

                StringBuilder strSql = new StringBuilder();
                strSql.Append(@"select  top 1 UserID,U_LoginName,U_Password,U_CName,U_EName,U_GroupID,U_Email,U_Type,U_Status,U_Licence,U_Mac,U_Remark,U_IDCard,U_Sex,U_BirthDay,U_MobileNo,U_UserNO,U_WorkStartDate,U_WorkEndDate,U_CompanyMail,U_Title,U_Extension,U_HomeTel,U_PhotoUrl,U_DateTime,U_LastIP,U_LastDateTime,U_ExtendField
                ,(select top 1 R_RoleID from dbo.sys_UserRoles where R_UserID=t.UserID) as RoleID from sys_User t ");
                strSql.Append(" where UserID=@UserID");
                SqlParameter[] parameters = {
					new SqlParameter("@UserID", SqlDbType.Int,4)
			    };
                parameters[0].Value = UserID;

                Slja.Model.Platform.UserModel model = new Slja.Model.Platform.UserModel();
                DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
                if (ds.Tables[0].Rows.Count > 0)
                {
                    AssignUserModel(ds.Tables[0].Rows[0], model);
                    return model;
                }
                else
                {
                    return null;
                }
            }
            public void AssignUserModel(DataRow dr, Slja.Model.Platform.UserModel model)
            {
                if (model != null)
                {
                    if (dr["UserID"] != null && dr["UserID"].ToString() != "")
                    {
                        model.UserID = int.Parse(dr["UserID"].ToString());
                    }
                    if (dr["U_LoginName"] != null && dr["U_LoginName"].ToString() != "")
                    {
                        model.U_LoginName = dr["U_LoginName"].ToString();
                    }
                    if (dr["U_Password"] != null && dr["U_Password"].ToString() != "")
                    {
                        model.U_Password = dr["U_Password"].ToString();
                    }
                    if (dr["U_CName"] != null && dr["U_CName"].ToString() != "")
                    {
                        model.U_CName = dr["U_CName"].ToString();
                    }
                    if (dr["U_EName"] != null && dr["U_EName"].ToString() != "")
                    {
                        model.U_EName = dr["U_EName"].ToString();
                    }
                    if (dr["U_GroupID"] != null && dr["U_GroupID"].ToString() != "")
                    {
                        model.U_GroupID = int.Parse(dr["U_GroupID"].ToString());
                    }
                    if (dr["U_Email"] != null && dr["U_Email"].ToString() != "")
                    {
                        model.U_Email = dr["U_Email"].ToString();
                    }
                    if (dr["U_Type"] != null && dr["U_Type"].ToString() != "")
                    {
                        model.U_Type = int.Parse(dr["U_Type"].ToString());
                    }
                    if (dr["U_Status"] != null && dr["U_Status"].ToString() != "")
                    {
                        model.U_Status = int.Parse(dr["U_Status"].ToString());
                    }
                    if (dr["U_Licence"] != null && dr["U_Licence"].ToString() != "")
                    {
                        model.U_Licence = dr["U_Licence"].ToString();
                    }
                    if (dr["U_Mac"] != null && dr["U_Mac"].ToString() != "")
                    {
                        model.U_Mac = dr["U_Mac"].ToString();
                    }
                    if (dr["U_Remark"] != null && dr["U_Remark"].ToString() != "")
                    {
                        model.U_Remark = dr["U_Remark"].ToString();
                    }
                    if (dr["U_IDCard"] != null && dr["U_IDCard"].ToString() != "")
                    {
                        model.U_IDCard = dr["U_IDCard"].ToString();
                    }
                    if (dr["U_Sex"] != null && dr["U_Sex"].ToString() != "")
                    {
                        model.U_Sex = int.Parse(dr["U_Sex"].ToString());
                    }
                    if (dr["U_BirthDay"] != null && dr["U_BirthDay"].ToString() != "")
                    {
                        model.U_BirthDay = DateTime.Parse(dr["U_BirthDay"].ToString());
                    }
                    if (dr["U_MobileNo"] != null && dr["U_MobileNo"].ToString() != "")
                    {
                        model.U_MobileNo = dr["U_MobileNo"].ToString();
                    }
                    if (dr["U_UserNO"] != null && dr["U_UserNO"].ToString() != "")
                    {
                        model.U_UserNO = dr["U_UserNO"].ToString();
                    }
                    if (dr["U_WorkStartDate"] != null && dr["U_WorkStartDate"].ToString() != "")
                    {
                        model.U_WorkStartDate = DateTime.Parse(dr["U_WorkStartDate"].ToString());
                    }
                    if (dr["U_WorkEndDate"] != null && dr["U_WorkEndDate"].ToString() != "")
                    {
                        model.U_WorkEndDate = DateTime.Parse(dr["U_WorkEndDate"].ToString());
                    }
                    if (dr["U_CompanyMail"] != null && dr["U_CompanyMail"].ToString() != "")
                    {
                        model.U_CompanyMail = dr["U_CompanyMail"].ToString();
                    }
                    if (dr["U_Title"] != null && dr["U_Title"].ToString() != "")
                    {
                        model.U_Title = int.Parse(dr["U_Title"].ToString());
                    }
                    if (dr["U_Extension"] != null && dr["U_Extension"].ToString() != "")
                    {
                        model.U_Extension = dr["U_Extension"].ToString();
                    }
                    if (dr["U_HomeTel"] != null && dr["U_HomeTel"].ToString() != "")
                    {
                        model.U_HomeTel = dr["U_HomeTel"].ToString();
                    }
                    if (dr["U_PhotoUrl"] != null && dr["U_PhotoUrl"].ToString() != "")
                    {
                        model.U_PhotoUrl = dr["U_PhotoUrl"].ToString();
                    }
                    if (dr["U_DateTime"] != null && dr["U_DateTime"].ToString() != "")
                    {
                        model.U_DateTime = DateTime.Parse(dr["U_DateTime"].ToString());
                    }
                    if (dr["U_LastIP"] != null && dr["U_LastIP"].ToString() != "")
                    {
                        model.U_LastIP = dr["U_LastIP"].ToString();
                    }
                    if (dr["U_LastDateTime"] != null && dr["U_LastDateTime"].ToString() != "")
                    {
                        model.U_LastDateTime = DateTime.Parse(dr["U_LastDateTime"].ToString());
                    }
                    if (dr["U_ExtendField"] != null && dr["U_ExtendField"].ToString() != "")
                    {
                        model.U_ExtendField = dr["U_ExtendField"].ToString();
                    }
                    if (dr.Table.Columns.Contains("RoleID") && dr["RoleID"] != DBNull.Value && dr["RoleID"].ToString() != "")
                    {
                        model.RoleID = int.Parse(dr["RoleID"].ToString());
                    }
                    if (dr.Table.Columns.Contains("R_RoleName") && dr["R_RoleName"] != DBNull.Value)
                    {
                        model.RoleName = dr["R_RoleName"].ToString();
                    }
                    if (dr.Table.Columns.Contains("G_CName") && dr["G_CName"] != DBNull.Value)
                    {
                        model.RoleName = dr["G_CName"].ToString();
                    }
                }
            }
            /// <summary>
            /// 获得数据列表
            /// </summary>
            public DataSet GetListFromPage(string strWhere, string strOrderby, int pageSize, int curPage, out int recordCount)
            {
                StringBuilder strSql = new StringBuilder();
                strSql.Append(@"select UserID,U_LoginName,U_Password,U_CName,U_EName,U_GroupID,U_Email,U_Type,U_Status,U_Licence,U_Mac,U_Remark,U_IDCard,U_Sex,U_BirthDay,U_MobileNo,U_UserNO,U_WorkStartDate,U_WorkEndDate,U_CompanyMail,U_Title,U_Extension,U_HomeTel,U_PhotoUrl,U_DateTime,U_LastIP,U_LastDateTime,U_ExtendField 
                        ,r.R_RoleName,ur.R_RoleID,g.G_CName
                        from dbo.sys_User u inner join dbo.sys_UserRoles ur on u.UserID=ur.R_UserID
                        left join dbo.sys_Roles r on ur.R_RoleID=r.RoleID
                        left join dbo.sys_Group g on u.U_GroupID=g.GroupID");              
                if (strWhere.Trim() != "")
                {
                    strSql.Append(" where " + strWhere);
                }

                return DALUti.GetPageData(strSql.ToString(), strOrderby, pageSize, curPage, out recordCount);
                
            }

            /// <summary>
            /// 获得前几行数据
            /// </summary>
            public DataSet GetList(int Top, string strWhere, string filedOrder)
            {
                StringBuilder strSql = new StringBuilder();
                strSql.Append("select ");
                if (Top > 0)
                {
                    strSql.Append(" top " + Top.ToString());
                }
                strSql.Append(" UserID,U_LoginName,U_Password,U_CName,U_EName,U_GroupID,U_Email,U_Type,U_Status,U_Licence,U_Mac,U_Remark,U_IDCard,U_Sex,U_BirthDay,U_MobileNo,U_UserNO,U_WorkStartDate,U_WorkEndDate,U_CompanyMail,U_Title,U_Extension,U_HomeTel,U_PhotoUrl,U_DateTime,U_LastIP,U_LastDateTime,U_ExtendField ");
                strSql.Append(" FROM sys_User ");
                if (strWhere.Trim() != "")
                {
                    strSql.Append(" where " + strWhere);
                }
                strSql.Append(" order by " + filedOrder);
                return DbHelperSQL.Query(strSql.ToString());
            }

            /// <summary>
            /// 获取记录总数
            /// </summary>
            public int GetRecordCount(string strWhere)
            {
                StringBuilder strSql = new StringBuilder();
                strSql.Append("select count(1) FROM sys_User ");
                if (strWhere.Trim() != "")
                {
                    strSql.Append(" where " + strWhere);
                }
                object obj = DbHelperSQL.GetSingle(strSql.ToString());
                if (obj == null)
                {
                    return 0;
                }
                else
                {
                    return Convert.ToInt32(obj);
                }
            }
            /// <summary>
            /// 分页获取数据列表
            /// </summary>
            public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
            {
                StringBuilder strSql = new StringBuilder();
                strSql.Append("SELECT * FROM ( ");
                strSql.Append(" SELECT ROW_NUMBER() OVER (");
                if (!string.IsNullOrEmpty(orderby.Trim()))
                {
                    strSql.Append("order by T." + orderby);
                }
                else
                {
                    strSql.Append("order by T.UserID desc");
                }
                strSql.Append(")AS Row, T.*  from sys_User T ");
                if (!string.IsNullOrEmpty(strWhere.Trim()))
                {
                    strSql.Append(" WHERE " + strWhere);
                }
                strSql.Append(" ) TT");
                strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
                return DbHelperSQL.Query(strSql.ToString());
            }

            /*
            /// <summary>
            /// 分页获取数据列表
            /// </summary>
            public DataSet GetList(int PageSize,int PageIndex,string strWhere)
            {
                SqlParameter[] parameters = {
                        new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                        new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                        new SqlParameter("@PageSize", SqlDbType.Int),
                        new SqlParameter("@PageIndex", SqlDbType.Int),
                        new SqlParameter("@IsReCount", SqlDbType.Bit),
                        new SqlParameter("@OrderType", SqlDbType.Bit),
                        new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                        };
                parameters[0].Value = "sys_User";
                parameters[1].Value = "UserID";
                parameters[2].Value = PageSize;
                parameters[3].Value = PageIndex;
                parameters[4].Value = 0;
                parameters[5].Value = 0;
                parameters[6].Value = strWhere;	
                return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
            }*/

            #endregion  Method
        }
    }
